package com.snake.springboot.custom.service.impl.base;

import com.snake.springboot.custom.api.model.base.CustCertModel;
import com.snake.springboot.custom.api.request.base.CustomAdminReq;
import com.snake.springboot.custom.api.request.base.CustomReq;
import com.snake.springboot.custom.api.response.base.CustomRsp;
import com.snake.springboot.custom.api.service.base.CustCertService;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustCertDO;
import com.snake.springboot.custom.dao.mybatis.mappers.base.CustCertMapper;
import com.snake.springboot.custom.service.assemble.base.CustCertAssembler;
import org.snake.common.utils.PropertyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CustCertServiceImpl implements CustCertService{

    @Autowired
    private CustCertMapper custCertMapper;

    @Override
    public void addCert(CustomReq customReq) {
        if (customReq.getCertModel()==null){
            customReq.setCertModel(new CustCertModel());
        }
        CustCertDO certDO = CustCertAssembler.certDOAss(customReq);
        custCertMapper.insert(certDO);
    }

    @Override
    public void queryDetail(CustomRsp rsp) {
        CustCertDO certDO = custCertMapper.queryById(rsp.getCustomId());
        CustCertModel certModel = new CustCertModel();
        PropertyUtils.copyPropertiesIfNull(certModel,certDO);
        rsp.setCertModel(certModel);
    }

    @Override
    public void modifyCert(CustCertModel model) {
        CustCertDO certDO = CustCertAssembler.certDOAss(model);
        custCertMapper.update(certDO);
    }

    @Override
    public void updateCert(CustomAdminReq model) {
        CustCertDO certDO = CustCertAssembler.certDOAss(model.getCertModel());
        custCertMapper.update(certDO);
    }
}
